package com.internetCafes.spms.common.AIRecognize.recognizer.impl;

import com.internetCafes.spms.common.AIRecognize.recognizer.Recognizer;
import com.internetCafes.spms.common.AIRecognize.Pic2WordAIUtils;
import com.internetCafes.spms.common.utils.entity.Pic2WordItem;
import com.internetCafes.spms.common.utils.entity.WordRetItem;
import com.internetCafes.spms.common.AIRecognize.analyzer.impl.WordAnalyzer;
import com.internetCafes.spms.web.certificate.vo.AIRecognizeInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author LinYe
 * @date 2020/10/14
 */
@Component
public class Pic2WordAIRecognizer implements Recognizer {

    @Autowired
    ApplicationContext applicationContext;

    @Autowired
    WordAnalyzer wordAnalyzer;

    @Override
    public AIRecognizeInfo recognize(String filePath) {
        Pic2WordItem pic2WordItem = Pic2WordAIUtils.ScanPic(filePath);
        if (pic2WordItem==null){
            return null;
        }
        List<WordRetItem> ret = pic2WordItem.getRet();
        String word = "";

        if (ret==null){
            return null;
        }
        for (int i = 0; i < ret.size(); i++) {
            WordRetItem wordRetItem = ret.get(i);
            word += wordRetItem.getWord() + "\n";
        }
        AIRecognizeInfo aiRecognizeInfo = wordAnalyzer.analyze(word, filePath);
        return aiRecognizeInfo;
    }
}
